<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .red {
        color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h2>todolist</h2>
      <input type="text" v-model="value" @keyup.enter="add" />
      <button @click="add">添加</button>

      <ul>
        <li
          v-for="item in list"
          :key="item.id"
          :class="{red: checkList.includes(item.id) }"
        >
          <input type="checkbox" v-model="checkList" :value="item.id" />
          {{ item.name }} - {{ item.id }}
          <button @click="del(item.id)">删除</button>
        </li>
      </ul>

      <p>checkList: {{ checkList }}</p>

      <button @click="removeAll">删除所选</button>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            value: "",
            list: [
              {
                id: 1,
                name: "zhangsan",
              },
              {
                id: 2,
                name: "lisi",
              },
            ],
            checkList: [],
          };
        },
        methods: {
          add() {
            // console.log(this.value);
            if (this.value) {
              this.list.push({
                id: new Date().getTime(),
                name: this.value,
                checked: false,
              });
              this.value = "";
            }
          },
          del(id) {
            console.log(id);
            this.list = this.list.filter((item) => item.id !== id);
          },
          removeAll() {
            this.list = this.list.filter(
              (item) => !this.checkList.includes(item.id)
            );
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
